<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">


<title>采购需求列表显示</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="content-type" content="text/html;charset=utf-8">

<link rel="stylesheet" href="js/easyui/demo/demo.css" type="text/css"></link>
<link rel="stylesheet" href="js/easyui/themes/icon.css" type="text/css"></link>
<link rel="stylesheet" href="js/easyui/themes/default/easyui.css"
	type="text/css"></link>
<script type="text/javascript" src="js/easyui/jquery-1.6.min.js"></script>
<script type="text/javascript" src="js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="script/common.js"></script>
<script type="text/javascript" src="js/easyui/themes/easyui-lang-zh_CN.js"></script>
<link href="css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">

</style>
<script type="text/javascript">
	/**
	 * 根据制定页面跳转
	 */
	function reload() {
		var offset = document.getElementById("offset").value;
		var idx = (offset == null) ? 0 : parseInt(offset) - 1;
			
		window.location = 'procurepgetAllProcurep?offset=' + idx;
	}
	
	/**
	 * 根据条件查询
	 */
	function query() {
		var productCode = $("#productCode").val();
		var suppelierCountSt = $("#suppelierCountSt").val();
		var suppelierCountEd = $("#suppelierCountEd").val();
		var createtimeSt = $("#createtimeSt").datebox('getValue');
		var createtimeEd = $("#createtimeEd").datebox('getValue');
		var status = $("#status").combobox("getValue");
		window.location = 'procurepgetAllProcurep?productCode='+productCode+'&suppelierCountSt='+suppelierCountSt
					+'&suppelierCountEd='+suppelierCountEd+'&createtimeSt='+createtimeSt+'&createtimeEd='+createtimeEd
					+'&status='+status;
		
	}
	
	/**
	* 翻到给定偏移量的页面
	*/
	function turnPage(offset){
		var productCode = $("#productCode").val();
		var suppelierCountSt = $("#suppelierCountSt").val();
		var suppelierCountEd = $("#suppelierCountEd").val();
		var createtimeSt = $("#createtimeSt").val;
		var createtimeEd = $("#createtimeEd").val;
		window.location = 'procurepgetAllProcurep?productCode='+productCode+'&suppelierCountSt='+suppelierCountSt
					+'&suppelierCountEd='+suppelierCountEd+'&createtimeSt='+createtimeSt+'&createtimeEd='+createtimeEd
					+'&offset=' + offset;			
	}
	
	/**
	 * 状态格式化
	 */
	 function statusFormater(val,row){
	 	val = val.trim();
		switch(val){
			case '0':
				val = "草稿";
			break;
			case '1':
				val= "询价中";
			break;
			case '2':
				val= "已报价";
			break;
			case '3':
				val= "生产中";
			break;
			case '4':
				val= "已完成";
			break;
			case '5':
				val= "已关闭";
			break;
		}
		return val;
	}
	
	/**
	 *编辑
	 */
	function editProcureProduct(procId,status){
		if(status == "0"){
		   addPanelExists("procurepgetEditByprocId?procId="+procId,"编辑采购需求");
		}else{
			$.messager.show({
					msg : '<div style="width:100%"><div style="line-height:40px;text-align:center;">只有草稿状态下可编辑！</div></div>',
					timeout : 800,
					showSpeed : 200,
					showType : 'show',
					style : {
						right : '',
						top : '200',
						bottom : ''
							}
					});
		}
		
	}
	
	
	
	/**
	 *删除
	 */
	function removeProcureProduct(productCode,procId,status){
		var msg = "确定要删除 ["+productCode+"] 采购需求吗？";
		if (confirm(msg) == true) {
			if(status == "0" || status== "1"){
				$.ajax({
					type:'POST',
					url:'procurepremoveProcurep',
					data:{
						'procId':procId
					},
					dataType : 'json',
					success : function(data){
						if(data){
							$.messager.show({
								msg : '<div style="width:100%"><div style="line-height:50px;text-align:center;">删除采购需求成功！</div></div>',
								timeout : 800,
								showSpeed : 200,
								showType : 'show',
								style : {
									right : '',
									top : '',
									bottom : ''
								}
							});
							window.location =  'procurepgetAllProcurep.action';
						}
					}
				});
			}else{
				$.messager.show({
					msg : '<div style="width:100%"><div style="line-height:40px;text-align:center;">只有草稿和发布状态下可删除！</div></div>',
					timeout : 800,
					showSpeed : 200,
					showType : 'show',
					style : {
						right : '',
						top : '200',
						bottom : ''
							}
					});
			}
			return true;
		}else{
			return false;
		}
		
	
	}
	
	//报价询价发布
	function showCandidateSuin(procId,status){
	 	if(status == "0"){
	 		//打开窗口
 			$('#suinList').window('open');
	 		$('#procId').val(procId);
	 	
	 		ulr="suingetCandidateSuins.action?procId="+procId;
	 		$('#suinList').window('refresh', ulr);  
	 	}else{
	 		$.messager.show({
					msg : '<div style="width:100%"><div style="line-height:40px;text-align:center;">只有草稿状态下可发布！</div></div>',
					timeout : 800,
					showSpeed : 200,
					showType : 'show',
					style : {
						right : '',
						top : '200',
						bottom : ''
							}
					});
	 	}
	 }
	
	/**
	 * 后审核供应商根据条件查询
	 */
	function queryCandidate(){
		var qsuid = $('#suid').val();
		var qsuna = $('#suna').val();
		$.ajax({
			type:'POST',
			url:'suinajaxCandidateSuins',
			data:{
				'qsuid':qsuid,
				'qsuna':qsuna
			},
			dataType : 'json',
			success : function(data){
				//修改datagrid的数据
				$('#candidateSuin').datagrid('loadData',data);
			}
		
		});
	
	}
	
	/**
	 *发布供应商需求
	 */
	function publish(){
		var procId=$("#procId").val();
		var sendTime =$("#sendTime").datebox('getValue');
		var endTime = $("#endTime").datebox('getValue');
		var remark = $("#remark").val();
		var rows = $("#candidateSuin").datagrid("getSelections"); // 获取所有选中的行
		
		var publishList = [];
		
		for (var i = 0; rows && i < rows.length; i++) {
			var procureInquiry = {};
			var row = rows[i];
			var index = $("#candidateSuin").datagrid("getRowIndex", row); // 获取该行的索引
			procureInquiry.procId = procId;
			procureInquiry.suid = row.suid;
			procureInquiry.sendTime = sendTime;
			procureInquiry.endTime = endTime;
			procureInquiry.remark = remark;
			publishList.push(procureInquiry);
		}
		var param = JSON.stringify(publishList);
		
		//验证必填项
	   	var isValid = $('#candidateSupplierForm').form('validate');
		if(isValid&&rows!=null){
			$.ajax({
				type : 'POST',
				url : 'procureppublishProcurep.action',
				data : {
					'param':param
				},
				dataType : 'json',
				success : function(data) {
			    	$("#suinList").window('close');
			    	
			    	$.messager.show({
					msg : '<div style="width:100%"><div style="line-height:40px;text-align:center;">需求已发布！</div></div>',
					timeout : 800,
					showSpeed : 200,
					showType : 'show',
					style : {
						right : '',
						top : '200',
						bottom : ''
							}
					});
					
					//刷新列表
					window.location =  'procurepgetAllProcurep.action';
				}
			});
		}
	}
	
	
	
	
</script>
</head>

<body>
	<div style="display: none;">
		<!-- 采购需求 询价单  -->
		<div id="suinList" class="easyui-window"  title="采购需求  询价单" collapsible="false"  minimizable="false"  maximizable="false" closed="true"  modal="true"
			 style="width:600px;height:540px; padding: 10px;" href=""> 
		</div> 
	</div>	
	<div style="margin:20px 20px 0px 20px; width:85%;">
		<div id="options" class="toolbar">
			<div style="width: 100%;float: none;">
				<div style="float: left;">
					<a onclick="addPanelExists('addpurchase.jsp','新增采购需求')" class="easyui-linkbutton"
						data-options="iconCls:'icon-add'" style="margin-right: 10px;">新增</a>
					<a href="procurepgetAllProcurep" class="easyui-linkbutton"
						data-options="iconCls:'icon-reload'" style="margin-right: 10px;">刷新</a>
				</div>
				<div style="float: left; margin-bottom: 10px;">
					<input class="easyui-textbox" type="text" id="productCode" prompt="产品款号" value="${productCode}" data-options="height:26">
					<input class="easyui-textbox" type="text" id="suppelierCountSt" prompt="供应商数量" value="${suppelierCountSt}" data-options="height:26">
					<span>-</span>
					<input class="easyui-textbox" type="text" id="suppelierCountEd" prompt="供应商数量" value="${suppelierCountEd}" data-options="height:26">
					<input class="easyui-datebox" type="text" id="createtimeSt" prompt="创建时间" value="${createtimeSt}" data-options="height:26">
					<span>-</span>
					<input class="easyui-datebox" type="text" id="createtimeEd" prompt="创建时间" value="${createtimeEd}" data-options="height:26">
				</div>
				<div style="float: left; margin-bottom: 10px;">
					<select id="status" class="easyui-combobox" style="width:148px;height:26px" prompt="状态" panelHeight="110"; editable="false">
						<option value="-1"></option>
						<option value="0" <c:if test="${status==0}"> selected="true"</c:if>>草稿</option>
						<option value="1" <c:if test="${status==1}"> selected="true"</c:if>>询价中</option>
						<option value="2" <c:if test="${status==2}"> selected="true"</c:if>>已报价</option>
						<option value="3" <c:if test="${status==3}"> selected="true"</c:if>>生产中</option>
						<option value="4" <c:if test="${status==4}"> selected="true"</c:if>>已完成</option>
						<option value="5" <c:if test="${status==5}"> selected="true"</c:if>>已关闭</option>
					</select>
				</div>
				<div style=" float: left;">
					<input class="easyui-linkbutton"
						type="button" id="query" style="margin-left: 15px;"
						onclick="query()" value="查询 ">
				</div>
			</div>
		</div>
		<div style="width:100%; float: left;" id = "show">
			<table class="easyui-datagrid" style="width:100%;" singleSelect="true">
				<thead>
					<tr>
						<th data-options="field:'procId'" width="">序号</th>
						<th data-options="field:'productCode'">产品款号</th>
						<th data-options="field:'blueprint '">设计图</th>
						<th data-options="field:'suppelierCount'">供应商数量</th>
						<th data-options="field:'procCount'">采购数量</th>
						<th data-options="field:'sysUser'">发布人员</th>
						<th data-options="field:'startTime'">开始时间</th>
						<th data-options="field:'endTime'">结束时间</th>
						<th data-options="field:'deliveryDate'">交货时间</th>
						<th data-options="field:'status'" formatter="statusFormater">状态</th>
						<th data-options="field:'操作'">操作</th>
					</tr>
				</thead>
				<c:choose>
					<c:when test="">
						<tr style="text-align: center;">
							<td colspan="11">
								<span style="color: grey;"></span>
							</td>
						</tr>
					</c:when>
					<c:otherwise>
						<c:forEach items="${procureplist}" var="ProcureProduct" varStatus="i">
							<tr>
								
								<td>
									<c:out value="${i.index+1+offset*10 }" />
								</td>
								
								<td>
									<c:out value="${ProcureProduct.productCode}" />
								</td>
								
								<td>
									<c:out value="${ProcureProduct.blueprint}" />
								</td>
								
								<td>
									<c:out value="${ProcureProduct.suppelierCount}" />
								</td>
								
								<td>
									<c:out value="${ProcureProduct.procCount}" />
								</td>
								
								<td>
									<c:out value="${ProcureProduct.sysUser}" />
								</td>
								
								<td>
									<fmt:setLocale value="zh_cn" /> 
									<a href="" title="${ProcureProduct.startTime}"><font><fmt:formatDate value="${ProcureProduct.startTime}" type="date" dateStyle="long" /></font></a>
								</td>
								
								<td>
									<fmt:setLocale value="zh_cn" /> 
									<a href="" title="${ProcureProduct.deliveryDate}"><font><fmt:formatDate value="${ProcureProduct.deliveryDate}" type="date" dateStyle="long" /></font></a>
								</td>
								<td>
									<fmt:setLocale value="zh_cn" /> 
									<a href="" title="${ProcureProduct.endTime}"><font><fmt:formatDate value="${ProcureProduct.endTime}" type="date" dateStyle="long" /></font></a>
								</td>
								
								<td>
									<c:out value="${ProcureProduct.status}"></c:out>
								</td>
								
								<td><a onclick="addPanelExists('procurepgetDetaPurchase?procId=${ProcureProduct.procId}','采购需求详情')" style="text-decoration: underline;">详情</a><b>|</b>
									<a onclick="editProcureProduct('${ProcureProduct.procId}','${ProcureProduct.status}')" style="text-decoration: underline;">编辑</a><b>|</b>
									<a onclick="removeProcureProduct('${ProcureProduct.productCode}','${ProcureProduct.procId}','${ProcureProduct.status}')" style="text-decoration: underline;">删除</a><b>|</b>
									<a onclick="showCandidateSuin('${ProcureProduct.procId}','${ProcureProduct.status}')" style="text-decoration: underline;">发布</a>
								</td>
							</tr>
						</c:forEach>
					</c:otherwise>
				</c:choose>
			</table>
			<div class="pager" id="pagebar">
				共<b id="ttCount">${totalcount }</b>条记录 转到&nbsp;<input value="${offset+1}" size="2" id="offset" class="easyui-textbox" />&nbsp;页/<b id="ttPage">${totalpage }</b>页
				<button class="easyui-linkbutton jump-btn" width="20" onclick="reload()">跳转</button>
				<a onclick="turnPage(0)">&lt;&lt; 第一页</a> <a
					onclick="turnPage(${offset-1})">&lt; 上一页</a> <a
					onclick="turnPage(${offset+1})">下一页 &gt;</a> <a
					onclick="turnPage(${totalpage-1})">最后一页 &gt;&gt;</a>
			</div>
		</div>
		<input  id="procId" style="display:none;" value="" /> 
	</div>

</body>
</html>
